﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.Text;

public partial class yuanliaojingjiafabu : System.Web.UI.Page
{
    protected string tableContent;
    DataSet ds = new DataSet();

    protected void Page_Load(object sender, EventArgs e)
    {
        GetBind();
    }

    protected void GetBind() {
        StringBuilder sb = new StringBuilder();
        string filePath = Server.MapPath("xmldata/yuanliaojingjiafabu.xml");
        ds.ReadXml(filePath);
        if (ds.Tables.Count>0)
        {
            DataTable dt = ds.Tables[0];
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                sb.Append("<tr>");
                sb.AppendFormat("<td style=\"height: 36px\">" + dt.Rows[i]["ID"].ToString() + "</td>");
                sb.AppendFormat("<td style=\"height: 36px\">" + dt.Rows[i]["NO"].ToString() + "</td>");
                sb.AppendFormat("<td style=\"height: 36px\">" + dt.Rows[i]["name"].ToString() + "</td>");
                sb.AppendFormat("<td style=\"height: 36px\">" + dt.Rows[i]["spec"].ToString() + "</td>");
                sb.AppendFormat("<td style=\"height: 36px\">" + dt.Rows[i]["end_delivery"].ToString() + "</td>");
                sb.AppendFormat("<td style=\"height: 36px\">" + dt.Rows[i]["required_delivery"].ToString() + "</td>");
                sb.AppendFormat("<td style=\"height: 36px\">" + dt.Rows[i]["note"].ToString() + "</td>");
                sb.Append("<td style=\"height: 36px\"><a href=\"#\">增加</a> <a href=\"#\">删除</a> <a href=\"yuanLiaoBidList.htm\">竞价(6)</a></td>");
                sb.Append("</tr>");
            }
            tableContent = sb.ToString();
        }
        else
        {
            sb.Append("<tr>");
            sb.Append("<td align=\"center\">暂无竞价消息！</td>");
            sb.Append("</tr>");
            tableContent = sb.ToString();
        }
    }
    protected void btnFabu_Click(object sender, EventArgs e)
    {
        string filePath = Server.MapPath("xmldata/yuanliaojingjiafabu.xml");
        string NO = Request.Form["NO"];
        string name = Request.Form["name"];
        string spec = Request.Form["spec"];
        string end_delivery = Request.Form["end_delivery"];
        string required_delivery = Request.Form["required_delivery"];
        string note = Request.Form["note"];

        XmlDataDocument xmlDoc = new XmlDataDocument();
        xmlDoc.Load(Server.MapPath("xmldata/yuanliaojingjiafabu.xml"));
        XmlNode xmldocSelect = xmlDoc.SelectSingleNode("messageList");
        XmlElement el = xmlDoc.CreateElement("field");
        DataTable dt = ds.Tables[0];
        string id = Convert.ToString(dt.Rows.Count + 1);
        el.SetAttribute("num",id);

        XmlElement elId = xmlDoc.CreateElement("ID");
        elId.InnerText = id;
        el.AppendChild(elId);

        XmlElement elNO = xmlDoc.CreateElement("NO");
        elNO.InnerText = NO;
        el.AppendChild(elNO);

        XmlElement elName = xmlDoc.CreateElement("name");
        elName.InnerText = name;
        el.AppendChild(elName);

        XmlElement elSpec = xmlDoc.CreateElement("spec");
        elSpec.InnerText = spec;
        el.AppendChild(elSpec);

        XmlElement elEs = xmlDoc.CreateElement("end_delivery");
        elEs.InnerText = end_delivery;
        el.AppendChild(elEs);

        XmlElement elRe = xmlDoc.CreateElement("required_delivery");
        elRe.InnerText = required_delivery;
        el.AppendChild(elRe);

        XmlElement elNote = xmlDoc.CreateElement("note");
        elNote.InnerText = note;
        el.AppendChild(elNote);

        xmldocSelect.AppendChild(el);
        xmlDoc.Save(Server.MapPath("xmldata/yuanliaojingjiafabu.xml"));

        Response.Redirect("yuanliaojingjiafabu.aspx");
    }
}
